package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "套餐相关接口")
@RestController
@RequestMapping("/admin/setmeal")
public class SetMealController {

    @Autowired
    private SetmealService setmealService;

    @ApiOperation("添加套餐接口")
    @PostMapping
    public Result addSetMeal(@RequestBody SetmealDTO setmealDTO){
            log.info("添加商品的信息为：{}",setmealDTO);
            setmealService.addSetMeal(setmealDTO);
           return Result.success();
    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> SelectById(@PathVariable Long id){
        log.info("查询套餐的id为：{}",id);
             SetmealVO setmealVO =  setmealService.getById(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("套餐的分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询：{}",setmealPageQueryDTO);

          PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
          return Result.success(pageResult);
    }

    @ApiOperation("修改套餐状态")
    @PostMapping("/status/{status}")
    public Result onsaveOroffsave(@PathVariable Integer status,Long id){
    setmealService.onsaveOroffsave(status,id);
    return Result.success();
    }

    @ApiOperation("根据Ids批量删除套餐")
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids){
    log.info("根据Ids批量删除套餐:{}",ids);
    setmealService.deleteByIds(ids);
    return Result.success();
    }


    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐：{}",setmealDTO);
        setmealService.updataSetmeal(setmealDTO);
        return Result.success();
    }

}
